package com.rslai.commons.validator.jsonvalidator.matchers;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

import static org.hamcrest.core.IsNull.notNullValue;

/**
 * 非空必须Matcher
 */
public class Required extends TypeSafeMatcher<Object> {

    /**
     * 构造函数
     * @param item item
     * @return boolean
     */
    @Override
    protected boolean matchesSafely(Object item) {
        return notNullValue().matches(item);
    }

    /**
     * 产生描述
     * @param description 描述
     */
    @Override
    public void describeTo(Description description) {
        description.appendText("required");
    }

    @Factory
    public static Matcher<Object> required() {
        return new Required();
    }

}
